

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/broswer.jpg">
  <link rel="icon" href="/img/broswer.jpg">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Feng Zikai">
  <meta name="keywords" content="">
  
    <meta name="description" content="主要是还在考试的过程中，完全不想准备考研，在知乎刷到了一篇关于现代c++的介绍，介绍了一些流行的第三方库，如google 的 abseil,facebook 的folly,所以想安装试一试。一般都需要编译安装，非常的麻烦，所以考虑使用msys2来安装，但是folly库msys2居然都没有,果然Windows 还是老老实实的用MSVC吧✌。Vcpkg经过几年的发展已经完全可用了，开源库都有Vcpk">
<meta property="og:type" content="article">
<meta property="og:title" content="vscode 配置msvc编译器 使用vcpkg进行C++包管理">
<meta property="og:url" content="http://example.com/2022/06/27/vscode%20%E9%85%8D%E7%BD%AEmsvc%E7%BC%96%E8%AF%91%E5%99%A8-%E4%BD%BF%E7%94%A8vcpkg%E8%BF%9B%E8%A1%8CC++%E5%8C%85%E7%AE%A1%E7%90%86/index.html">
<meta property="og:site_name" content="F7kyyy的博客">
<meta property="og:description" content="主要是还在考试的过程中，完全不想准备考研，在知乎刷到了一篇关于现代c++的介绍，介绍了一些流行的第三方库，如google 的 abseil,facebook 的folly,所以想安装试一试。一般都需要编译安装，非常的麻烦，所以考虑使用msys2来安装，但是folly库msys2居然都没有,果然Windows 还是老老实实的用MSVC吧✌。Vcpkg经过几年的发展已经完全可用了，开源库都有Vcpk">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/image-20220627221709538.png">
<meta property="article:published_time" content="2022-06-27T13:58:53.000Z">
<meta property="article:modified_time" content="2023-07-09T13:47:12.000Z">
<meta property="article:author" content="Feng Zikai">
<meta property="article:tag" content="环境配置">
<meta property="article:tag" content="C++">
<meta property="article:tag" content="Visual Studio Code">
<meta property="article:tag" content="Visual Studio">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/image-20220627221709538.png">
  
  
  
  <title>vscode 配置msvc编译器 使用vcpkg进行C++包管理 - F7kyyy的博客</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  



  
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.5-a","typing":{"enable":true,"typeSpeed":60,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading1.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>F7kyyy&#39;s blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="vscode 配置msvc编译器 使用vcpkg进行C++包管理"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-06-27 21:58" pubdate>
          2022年6月27日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          11k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          88 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">vscode 配置msvc编译器 使用vcpkg进行C++包管理</h1>
            
            
              <div class="markdown-body">
                
                <blockquote>
<p>主要是还在考试的过程中，完全不想准备考研，在知乎刷到了一篇关于现代c++的介绍，介绍了一些流行的第三方库，如google 的 <code>abseil</code>,facebook 的<code>folly</code>,所以想安装试一试。一般都需要编译安装，非常的麻烦，所以考虑使用msys2来安装，但是<code>folly</code>库msys2居然都没有,果然Windows 还是老老实实的用MSVC吧✌。Vcpkg经过几年的发展已经完全可用了，开源库都有Vcpkg的安装方式。</p>
</blockquote>
<h3 id="1-安装Visual-Studio-2022"><a href="#1-安装Visual-Studio-2022" class="headerlink" title="1. 安装Visual Studio 2022"></a>1. 安装Visual Studio 2022</h3><p>我们可以选择只安装<a target="_blank" rel="noopener" href="https://visualstudio.microsoft.com/zh-hans/downloads/">MS Build Toos</a>,但是当我们选择最基本的C++开发组件，大概需要4G左右存储空间，语言包需要额外选上英文，这是Vcpkg依赖。</p>
<img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/image-20220627223858130.png" srcset="/img/loading1.gif" lazyload alt="image-20220627223858130" style="zoom:50%;" />

<p>不过，我们为什么不选择直接安装Visual Studio 2022 ，体验一下宇宙第一IDE，毕竟完整安装也只要8G左右空间。<strong>强烈建议直接安装完整版，因为只安装开发工具的话想要再次完整安装会重新下载另外一份开发工具，十分扯淡</strong>，同样的<code>语言包需要额外选上英文</code></p>
<img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/image-20220627224405597.png" srcset="/img/loading1.gif" lazyload alt="image-20220627224405597" style="zoom:50%;" />

<h3 id="2-安装Vcpkg"><a href="#2-安装Vcpkg" class="headerlink" title="2. 安装Vcpkg"></a>2. 安装Vcpkg</h3><p><a target="_blank" rel="noopener" href="https://github.com/microsoft/vcpkg/blob/master/README_zh_CN.md#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B-windows">Github 官网有完整教程</a></p>
<h4 id="2-1-安装"><a href="#2-1-安装" class="headerlink" title="2.1 安装"></a>2.1 安装</h4><p>官方文档建议安装在<code>C:\src</code>目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs bash">git <span class="hljs-built_in">clone</span> https://github.com/microsoft/vcpkg<br>.\vcpkg\bootstrap-vcpkg.bat<br></code></pre></td></tr></table></figure>

<p>建议将<code>C:\src\vcpkg</code>加入环境变量，这样就可以在任意位置使用vcpkg命令</p>
<h4 id="2-2-基本操作"><a href="#2-2-基本操作" class="headerlink" title="2.2 基本操作"></a>2.2 基本操作</h4><figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs powershell"><span class="hljs-comment"># 搜索</span><br>vcpkg search [<span class="hljs-type">search</span> <span class="hljs-type">term</span>]<br><span class="hljs-comment"># 安装</span><br>vcpkg install [<span class="hljs-type">packages</span> <span class="hljs-type">to</span> <span class="hljs-type">install</span>]<br></code></pre></td></tr></table></figure>

<p>例如安装格式化库<code>fmt</code>，因为C++编译器的变化，直接下载二进制包是无法使用的，所以vcpkg相当于是将依赖源码全都下载然后编译，所以比较大的库时间还是比较长，比如OpenCV就需要可能20分钟，小的库也就几十秒</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs powershell">vcpkg search fmt<br><span class="hljs-comment"># 指定系统版本</span><br>vcpkg install fmt:x64<span class="hljs-literal">-windows</span><br></code></pre></td></tr></table></figure>

<img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/image-20220627225537803.png" srcset="/img/loading1.gif" lazyload alt="image-20220627225537803" style="zoom:50%;" />

<img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/image-20220627225902749.png" srcset="/img/loading1.gif" lazyload alt="image-20220627225902749" style="zoom:50%;" />

<h3 id="3-集成在VS中"><a href="#3-集成在VS中" class="headerlink" title="3.集成在VS中"></a>3.集成在VS中</h3><h4 id="3-1-全局集成"><a href="#3-1-全局集成" class="headerlink" title="3.1 全局集成"></a>3.1 全局集成</h4><p>执行下命令，直接新建一个VS项目，即可使用。</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs powershell">vcpkg integrate install<br></code></pre></td></tr></table></figure>

<img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/image-20220627231533379.png" srcset="/img/loading1.gif" lazyload alt="image-20220627231533379" style="zoom: 40%;" />

<h4 id="3-2-工程集成和CMake集成"><a href="#3-2-工程集成和CMake集成" class="headerlink" title="3.2 工程集成和CMake集成"></a>3.2 工程集成和CMake集成</h4><p>详见github</p>
<h3 id="4-在VS-code-Clion中使用"><a href="#4-在VS-code-Clion中使用" class="headerlink" title="4. 在VS code Clion中使用"></a>4. 在VS code Clion中使用</h3><p>这个项目是同时使用<code>OpenCV</code>,<code>fmt</code>库</p>
<img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/image-20220627233132298.png" srcset="/img/loading1.gif" lazyload alt="image-20220627233132298" style="zoom: 40%;" />

<p><code>测试代码</code></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_"># </span><span class="language-bash">opencv太大可以只测试前两个</span><br>vcpkg install fmt:x64-windows abseil:x64-windows opencv:x64-windows<br></code></pre></td></tr></table></figure>

<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><code class="hljs c++"><span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string">&lt;iostream&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string">&lt;vector&gt;</span></span><br><span class="hljs-comment">//#include &lt;opencv2/core/core.hpp&gt;</span><br><span class="hljs-comment">//#include &lt;opencv2/highgui/highgui.hpp&gt;</span><br><span class="hljs-comment">//#include &lt;opencv2/core/utils/logger.hpp&gt;</span><br><span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string">&lt;fmt/format.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string">&lt;absl/strings/str_format.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string">&lt;absl/strings/str_join.h&gt;</span></span><br><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">formatxx</span><span class="hljs-params">()</span> </span>&#123;<br>    <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> first = <span class="hljs-number">1</span>; first &lt; <span class="hljs-number">10</span>; first++) &#123;<br>        <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> second = <span class="hljs-number">1</span>; second &lt; first + <span class="hljs-number">1</span>; second++) &#123;<br>            <span class="hljs-keyword">auto</span> str = fmt::format(<span class="hljs-string">&quot;&#123;1&#125;*&#123;0&#125;=&#123;2:&lt;2&#125;&quot;</span>, first, second, first * second);<br>            std::cout &lt;&lt; str &lt;&lt; <span class="hljs-string">&quot; &quot;</span>;<br>        &#125;<br>        std::cout &lt;&lt; std::endl;<br>    &#125;<br>&#125;<br><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">testabseil</span><span class="hljs-params">()</span> </span>&#123;<br>    std::vector&lt;std::string&gt; v&#123; <span class="hljs-string">&quot;foo&quot;</span>, <span class="hljs-string">&quot;bar&quot;</span>, <span class="hljs-string">&quot;baz&quot;</span> &#125;;<br>    std::string s = absl::<span class="hljs-built_in">StrJoin</span>(v, <span class="hljs-string">&quot;-&quot;</span>);<br>    fmt::<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;&#123;0&#125;\n&quot;</span>, s);<br>&#125;<br><br><span class="hljs-comment">//void testOpenCV() &#123;</span><br><span class="hljs-comment">//    cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_SILENT);</span><br><span class="hljs-comment">//    cv::Mat myMat = cv::imread(&quot;C:/Users/FengisZZZ/Pictures/blog/head.jpg&quot;);</span><br><span class="hljs-comment">//    std::string s = fmt::format(&quot;&#123;0&#125; is &#123;1&#125;&quot;, &quot;abra&quot;, 12);</span><br><span class="hljs-comment">//    std::cout &lt;&lt; s &lt;&lt; std::endl;</span><br><span class="hljs-comment">//    fmt::print(&quot;Elapsed time: &#123;0:.2f&#125; seconds\n&quot;, 1.2783);</span><br><span class="hljs-comment">//    int height = myMat.cols;</span><br><span class="hljs-comment">//    int width = myMat.rows;</span><br><span class="hljs-comment">//    fmt::print(&quot;the width:&#123;0&#125;,the height:&#123;1&#125;\n&quot;, width, height);</span><br><span class="hljs-comment">//    cv::imshow(&quot;头像&quot;, myMat);</span><br><span class="hljs-comment">//    cv::waitKey();</span><br><span class="hljs-comment">//&#125;</span><br><br><span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">main</span><span class="hljs-params">(<span class="hljs-type">int</span> argc, <span class="hljs-type">char</span> <span class="hljs-type">const</span>* argv[])</span> </span>&#123;<br><br>    std::string s = fmt::format(<span class="hljs-string">&quot;&#123;0&#125; is &#123;1&#125;&quot;</span>, <span class="hljs-string">&quot;abra&quot;</span>, <span class="hljs-number">12</span>);<br>    std::cout &lt;&lt; s &lt;&lt; std::endl;<br>    fmt::<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;时间: &#123;0:.2f&#125; 秒\n&quot;</span>, <span class="hljs-number">1.2783</span>);<br>    fmt::<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;------------------------------------------------\n&quot;</span>);<br>    <span class="hljs-built_in">testabseil</span>();<br>    formatxx();<br>    <span class="hljs-comment">// testOpenCV();</span><br>&#125;<br></code></pre></td></tr></table></figure>



<h4 id="4-1-必须"><a href="#4-1-必须" class="headerlink" title="4.1 必须"></a>4.1 必须</h4><ul>
<li><p><strong>VScode setting.json</strong></p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-attr">&quot;cmake.configureSettings&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>    <span class="hljs-attr">&quot;CMAKE_TOOLCHAIN_FILE&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake&quot;</span><br><span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br></code></pre></td></tr></table></figure>


</li>
<li><p><strong>CMakeLists.txt</strong></p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs cmake"><span class="hljs-keyword">cmake_minimum_required</span>(VERSION <span class="hljs-number">3.0</span>.<span class="hljs-number">0</span>)<br><span class="hljs-keyword">project</span>(vcpkg_cmake VERSION <span class="hljs-number">0.1</span>.<span class="hljs-number">0</span>)<br><br><span class="hljs-keyword">set</span>(CMAKE_CXX_STANDARD <span class="hljs-number">17</span>)<br><span class="hljs-comment"># 添加编译选项，源代码为utf-8选项，中文不乱码</span><br><span class="hljs-keyword">add_compile_options</span>(/source-charset:utf-<span class="hljs-number">8</span>)<br><br><span class="hljs-keyword">find_package</span>(fmt CONFIG REQUIRED)<br><span class="hljs-comment"># find_package(OpenCV CONFIG REQUIRED)</span><br><span class="hljs-keyword">find_package</span>(absl CONFIG REQUIRED)<br><br><span class="hljs-keyword">add_executable</span>(vcpkg_cmake main.cpp)<br><br><span class="hljs-keyword">target_link_libraries</span>(<span class="hljs-variable">$&#123;PROJECT_NAME&#125;</span> PRIVATE fmt::fmt)<br><span class="hljs-comment"># target_link_libraries($&#123;PROJECT_NAME&#125; PRIVATE $&#123;OpenCV_LIBRARIES&#125;)</span><br><span class="hljs-keyword">target_link_libraries</span>(<span class="hljs-variable">$&#123;PROJECT_NAME&#125;</span> PRIVATE absl::any absl::base absl::bits absl::city)<br></code></pre></td></tr></table></figure>

<p><strong>将 vcpkg 作为一个子模块</strong></p>
<p>当您希望将vcpkg作为一个子模块加入到您的工程中时， 您可以在第一个 <code>project()</code> 调用之前将以下内容添加到 CMakeLists.txt 中， 而无需将 <code>CMAKE_TOOLCHAIN_FILE</code> 传递给cmake调用。</p>
<figure class="highlight gams"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs gams"><span class="hljs-keyword">set</span>(CMAKE_TOOLCHAIN_FILE <span class="hljs-comment">&quot;$&#123;CMAKE_CURRENT_SOURCE_DIR&#125;/vcpkg/scripts/buildsystems/vcpkg.cmake&quot;</span><br>  CACHE <span class="hljs-comment">STRING</span> <span class="hljs-comment">&quot;Vcpkg toolchain file&quot;</span><span class="hljs-comment">)</span><br></code></pre></td></tr></table></figure>

<p>使用此种方式可无需设置 <code>CMAKE_TOOLCHAIN_FILE</code> 即可使用vcpkg，且更容易完成配置工作。</p>
<p>这种方法可能存在问题，建议直接设置Cmake Path</p>
</li>
<li><p><code>Clion中</code>， 在<code>CMake Setting</code>中设置 ，在 <code>CMake options</code>添加一行, </p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs awk">-DCMAKE_TOOLCHAIN_FILE=[vcpkg root]<span class="hljs-regexp">/scripts/</span>buildsystems/vcpkg.cmake<br></code></pre></td></tr></table></figure>

<p>每个项目都要添加</p>
</li>
</ul>
<h4 id="4-2-优化"><a href="#4-2-优化" class="headerlink" title="4.2 优化"></a>4.2 优化</h4><ul>
<li><p>setting.json(全局)</p>
<ul>
<li>使用MSVC的工具链，但是生成Ninja更加简洁,生成compile_commands.json，为clangd插件提供补全</li>
<li>CMAKE_TOOLCHAIN_FILE 可以加载Vcpkg的包</li>
<li>clangd插件使用插件自己安装的clangd，同时提供了某些头文件</li>
</ul>
<p><code>Ninja</code>使用预发布的版本在使用会有警告，可以选择github下载自己编译<a target="_blank" rel="noopener" href="https://github.com/ninja-build/ninja">Ninja github page</a></p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-attr">&quot;cmake.configureSettings&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>    <span class="hljs-attr">&quot;CMAKE_TOOLCHAIN_FILE&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake&quot;</span><br><span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br><span class="hljs-attr">&quot;cmake.generator&quot;</span><span class="hljs-punctuation">:</span><span class="hljs-string">&quot;Ninja&quot;</span><span class="hljs-punctuation">,</span><br><span class="hljs-attr">&quot;clangd.path&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;c:\\Users\\f7ky\\AppData\\Roaming\\Code\\User\\globalStorage\\llvm-vs-code-extensions.vscode-clangd\\install\\14.0.3\\clangd_14.0.3\\bin\\clangd.exe&quot;</span><br></code></pre></td></tr></table></figure>
</li>
<li><p>setting.json (工作区) </p>
<ul>
<li>clangd配置；</li>
<li>在使用cmake插件debug时将结果输出在终端中；</li>
<li>关闭C&#x2F;C++语言功能，减少冲突；</li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-punctuation">&#123;</span><br>    <span class="hljs-attr">&quot;clangd.arguments&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>        <span class="hljs-comment">// 在后台自动分析文件（基于complie_commands)</span><br>        <span class="hljs-string">&quot;--background-index&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">//cmake生成json位置</span><br>        <span class="hljs-string">&quot;--compile-commands-dir=$&#123;workspaceFold&#125;$/build&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// clangd在创建索引使用的线程数</span><br>        <span class="hljs-string">&quot;-j=6&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// 启用 Clang-Tidy 以提供静态检查</span><br>        <span class="hljs-string">&quot;--clang-tidy&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// 建议风格：重载函数只会给出一个建议；反可以设置为detailed</span><br>        <span class="hljs-string">&quot;--completion-style=bundled&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// 启用,补全函数时，将会给参数提供占位符</span><br>        <span class="hljs-string">&quot;--function-arg-placeholders=false&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// 是否添加头文件</span><br>        <span class="hljs-string">&quot;--header-insertion=never&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// 输入建议中，已包含头文件的项与还未包含头文件的项会以圆点加以区分</span><br>        <span class="hljs-comment">// &quot;--header-insertion-decorators&quot;,</span><br>        <span class="hljs-comment">// 让 Clangd 生成更详细的日志</span><br>        <span class="hljs-string">&quot;--log=verbose&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// pch存储在内存中，内存消耗更大，但是性能更优</span><br>        <span class="hljs-string">&quot;--pch-storage=memory&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// 输出的 JSON 文件更美观</span><br>        <span class="hljs-string">&quot;--pretty&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-comment">// 设置项目，或者用户config</span><br>        <span class="hljs-string">&quot;--enable-config&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-comment">// cmake-tools图形化 debug 结果输出在integratedTerminal</span><br>    <span class="hljs-comment">// 因为只有使用MSVC工具链才有&quot;console&quot;选项，使用Mingw-64可能是&quot;integratedTerminal&quot;,与launch.json相同</span><br>    <span class="hljs-attr">&quot;cmake.debugConfig&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>        <span class="hljs-attr">&quot;console&quot;</span><span class="hljs-punctuation">:</span><span class="hljs-string">&quot;integratedTerminal&quot;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-attr">&quot;presentation&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>            <span class="hljs-attr">&quot;reveal&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;always&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;panel&quot;</span><span class="hljs-punctuation">:</span><span class="hljs-string">&quot;new&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;close&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;clear&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><br>        <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-attr">&quot;C_Cpp.intelliSenseEngine&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Disabled&quot;</span><br><span class="hljs-punctuation">&#125;</span><br></code></pre></td></tr></table></figure>
</li>
<li><p>launch.json</p>
<ul>
<li>快捷键调试的参数</li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-punctuation">&#123;</span><br>    <span class="hljs-attr">&quot;version&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;0.2.0&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-attr">&quot;configurations&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>        <span class="hljs-punctuation">&#123;</span><br>            <span class="hljs-attr">&quot;name&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;MSVC&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;cppvsdbg&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;request&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;launch&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;program&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;command:cmake.launchTargetPath&#125;&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;stopAtEntry&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;cwd&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;environment&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;console&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;integratedTerminal&quot;</span><span class="hljs-punctuation">,</span><br>             <span class="hljs-attr">&quot;presentation&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;reveal&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;always&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;panel&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;new&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;close&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;clear&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>        <span class="hljs-punctuation">&#125;</span><br>    <span class="hljs-punctuation">]</span><br><span class="hljs-punctuation">&#125;</span><br></code></pre></td></tr></table></figure>
</li>
<li><p>tasks.json</p>
<p><img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/202207272052066.gif" srcset="/img/loading1.gif" lazyload alt="tasks"></p>
</li>
</ul>
<h3 id="5-VScode使用MSVC单文件编译"><a href="#5-VScode使用MSVC单文件编译" class="headerlink" title="5. VScode使用MSVC单文件编译"></a>5. VScode使用MSVC单文件编译</h3><p><strong>正常使用需要从VS命令行窗口打开</strong></p>
<img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/202206302219889.png" srcset="/img/loading1.gif" lazyload alt="image-20220629141805160" style="zoom: 40%;" />

<p>观察到从命令实际上上启动了一个批处理命令，相当于配置了MSVC的环境变量,图中的命令需要使用<code> &quot;type&quot;: &quot;shell&quot;</code></p>
<img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/image-20220629142144595.png" srcset="/img/loading1.gif" lazyload alt="image-20220629142144595" style="zoom: 40%;" />

<p><code>&quot;type&quot;: &quot;cppbuild&quot;</code>需要此目录下的</p>
<img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/image-20220630220746980.png" srcset="/img/loading1.gif" lazyload alt="image-20220630220746980" style="zoom: 67%;" />

<p>所以我们只需要tasks.json执行这个命令</p>
<h4 id="5-1-tasks-json"><a href="#5-1-tasks-json" class="headerlink" title="5.1 tasks.json"></a>5.1 tasks.json</h4><p><code>vcvarsall.bat</code>相当于是配置环境变量；<code>x64</code>生成64位的可执行文件；添加位置是指定中间文件的输出位置</p>
<p><img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/image-20220629144006206.png" srcset="/img/loading1.gif" lazyload alt="image-20220629144006206"></p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-punctuation">&#123;</span><br>    <span class="hljs-attr">&quot;tasks&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>        <span class="hljs-punctuation">&#123;</span><br>            <span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;cppbuild&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;label&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Compile&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;command&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;\&quot;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat\&quot; x64 &amp;&amp; cl.exe&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>                <span class="hljs-string">&quot;/std:c++20&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;/Zi&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;/EHsc&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;/nologo&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;/O2&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;/W1&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;/source-charset:utf-8&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;/Fd$&#123;workspaceFolder&#125;\\bin\\&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;/Fo$&#123;workspaceFolder&#125;\\bin\\$&#123;fileBasenameNoExtension&#125;.obj&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;/Fe$&#123;workspaceFolder&#125;\\bin\\$&#123;fileBasenameNoExtension&#125;.exe&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;$&#123;file&#125;&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-string">&quot;/openmp:llvm&quot;</span><br>            <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;options&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;cwd&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;&quot;</span><br>            <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;problemMatcher&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>                <span class="hljs-string">&quot;$msCompile&quot;</span><br>            <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;group&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;kind&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;build&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;isDefault&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><br>            <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>			<span class="hljs-attr">&quot;presentation&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">&#123;</span><br>                <span class="hljs-attr">&quot;reveal&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;always&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;panel&quot;</span><span class="hljs-punctuation">:</span><span class="hljs-string">&quot;shared&quot;</span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;close&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span><br>                <span class="hljs-attr">&quot;clear&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><br>            <span class="hljs-punctuation">&#125;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;detail&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;调试器生成的任务。&quot;</span><br>        <span class="hljs-punctuation">&#125;</span><br>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-attr">&quot;version&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;2.0.0&quot;</span><br><span class="hljs-punctuation">&#125;</span><br></code></pre></td></tr></table></figure>

<p>也可以直接指定规定的模式,不需要指定x64</p>
<img src="https://cdn.jsdelivr.net/gh/F7kyyy/picture@main/img/image-20220629144457736.png" srcset="/img/loading1.gif" lazyload alt="image-20220629144457736" style="zoom: 80%;" />

<p><code>args</code>是编译选项，在<a target="_blank" rel="noopener" href="https://docs.microsoft.com/zh-cn/cpp/build/reference/align-section-alignment?view=msvc-170">官方网站</a>，可以查看每个编译选项的含义，中文版的，非常nice</p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><code class="hljs awk"><span class="hljs-regexp">//</span> c++标准是c++<span class="hljs-number">20</span><br><span class="hljs-string">&quot;/std:c++20&quot;</span>,<br><br><span class="hljs-regexp">//</span> 保留完整的调试信息，不加的化没办法打断点<br><span class="hljs-string">&quot;/Zi&quot;</span>,<br><br><span class="hljs-regexp">//</span> 标准 c + + 异常处理模型的完全编译器<br><span class="hljs-string">&quot;/EHsc&quot;</span>,<br><br><span class="hljs-regexp">//</span> 在编译器启动时禁止显示版权横幅，在编译过程中显示信息性消息<br><span class="hljs-string">&quot;/nologo&quot;</span>,<br><br><span class="hljs-regexp">//</span> 编译器选项是一次设置多个特定优化选项的一种快速方法<br><span class="hljs-string">&quot;/O2&quot;</span>,<br><br><span class="hljs-regexp">//</span> W1 显示等级 <span class="hljs-number">1</span> (只显示严重) 警告。 /W1 是命令行编译器中的默认设置。<br><span class="hljs-string">&quot;/W1&quot;</span>,<br><br><br><span class="hljs-regexp">//</span> 设置编码<br><span class="hljs-string">&quot;/source-charset:utf-8&quot;</span>,<br><br><span class="hljs-regexp">//</span> 没有 /Fd，PDB 文件名默认为 VCx0.pdb，其中 x 是当前Visual C++版本,指定输出位置<br><span class="hljs-string">&quot;/Fd$&#123;workspaceFolder&#125;\\bin\\&quot;</span>,<br><br><span class="hljs-regexp">//</span> 为 CL 编译器命令生成的所有对象文件设置输出目录<br><span class="hljs-string">&quot;/Fo$&#123;workspaceFolder&#125;\\bin\\$&#123;fileBasenameNoExtension&#125;.obj&quot;</span>,<br><br><span class="hljs-regexp">//</span> 指定编译器创建的 .exe或 DLL 的名称和目录<br><span class="hljs-string">&quot;/Fe$&#123;workspaceFolder&#125;\\bin\\$&#123;fileBasenameNoExtension&#125;.exe&quot;</span>,<br><br><span class="hljs-string">&quot;$&#123;file&#125;&quot;</span>,<br><br></code></pre></td></tr></table></figure>



<h4 id="5-2-launch-json"><a href="#5-2-launch-json" class="headerlink" title="5.2 launch.json"></a>5.2 launch.json</h4><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-punctuation">&#123;</span><br>    <span class="hljs-attr">&quot;version&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;0.2.0&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-attr">&quot;configurations&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>        <span class="hljs-punctuation">&#123;</span><br>            <span class="hljs-attr">&quot;name&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;(Windows) DEBUG&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;type&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;cppvsdbg&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;request&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;launch&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;program&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;\\bin\\$&#123;fileBasenameNoExtension&#125;.exe&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;args&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;stopAtEntry&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;cwd&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;$&#123;workspaceFolder&#125;&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;environment&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;internalConsoleOptions&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;neverOpen&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;console&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;integratedTerminal&quot;</span><span class="hljs-punctuation">,</span><br>            <span class="hljs-attr">&quot;preLaunchTask&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Compile&quot;</span><br>        <span class="hljs-punctuation">&#125;</span><br>    <span class="hljs-punctuation">]</span><br><span class="hljs-punctuation">&#125;</span><br></code></pre></td></tr></table></figure>

<h4 id="5-3-setting-json"><a href="#5-3-setting-json" class="headerlink" title="5.3  setting.json"></a>5.3  setting.json</h4><p>在使用单文件编译时，如果禁用<code>c/c++</code>语言插件功能,在编译错误时提示编译错误，但是会自动运行上一次正确的编译结果，因此不能禁用</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-comment">// 不能直接禁用</span><br><span class="hljs-comment">// &quot;C_Cpp.intelliSenseEngine&quot;: &quot;Disabled&quot;,</span><br><br><span class="hljs-attr">&quot;C_Cpp.autocomplete&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Disabled&quot;</span><span class="hljs-punctuation">,</span><br><span class="hljs-attr">&quot;C_Cpp.errorSquiggles&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Disabled&quot;</span><span class="hljs-punctuation">,</span><br><span class="hljs-attr">&quot;clangd.arguments&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><br>    <span class="hljs-comment">// 在后台自动分析文件（基于complie_commands)</span><br>    <span class="hljs-string">&quot;--background-index&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-comment">//cmake生成json位置</span><br>    <span class="hljs-string">&quot;--compile-commands-dir=$&#123;workspaceFold&#125;$/build&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-comment">// clangd在创建索引使用的线程数</span><br>    <span class="hljs-string">&quot;-j=6&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-comment">// 启用 Clang-Tidy 以提供静态检查</span><br>    <span class="hljs-string">&quot;--clang-tidy&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-comment">// 建议风格：重载函数只会给出一个建议；反可以设置为detailed</span><br>    <span class="hljs-string">&quot;--completion-style=bundled&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-comment">// 启用,补全函数时，将会给参数提供占位符</span><br>    <span class="hljs-string">&quot;--function-arg-placeholders=false&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-comment">// 是否添加头文件</span><br>    <span class="hljs-string">&quot;--header-insertion=never&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-comment">// 输入建议中，已包含头文件的项与还未包含头文件的项会以圆点加以区分</span><br>    <span class="hljs-comment">// &quot;--header-insertion-decorators&quot;,</span><br>    <span class="hljs-comment">// 让 Clangd 生成更详细的日志</span><br>    <span class="hljs-string">&quot;--log=verbose&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-comment">// pch存储在内存中，内存消耗更大，但是性能更优</span><br>    <span class="hljs-string">&quot;--pch-storage=memory&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-comment">// 输出的 JSON 文件更美观</span><br>    <span class="hljs-string">&quot;--pretty&quot;</span><span class="hljs-punctuation">,</span><br>    <span class="hljs-comment">// 设置项目，或者用户config</span><br>    <span class="hljs-string">&quot;--enable-config&quot;</span><span class="hljs-punctuation">,</span><br><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span><br></code></pre></td></tr></table></figure>


                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE/" class="category-chain-item">环境配置</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE/" class="print-no-link">#环境配置</a>
      
        <a href="/tags/C/" class="print-no-link">#C++</a>
      
        <a href="/tags/Visual-Studio-Code/" class="print-no-link">#Visual Studio Code</a>
      
        <a href="/tags/Visual-Studio/" class="print-no-link">#Visual Studio</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>vscode 配置msvc编译器 使用vcpkg进行C++包管理</div>
      <div>http://example.com/2022/06/27/vscode 配置msvc编译器-使用vcpkg进行C++包管理/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Feng Zikai</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年6月27日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/10/15/%E5%85%AC%E6%B0%91%E5%8F%82%E4%B8%8E%E7%A4%BE%E5%8C%BA%E6%B2%BB%E7%90%86%E9%87%87%E8%AE%BF%E4%B8%8E%E8%B0%83%E6%9F%A5/" title="公民参与社区治理采访与调查">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">公民参与社区治理采访与调查</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/05/08/%E8%A7%A3%E5%86%B3wsl2%E4%BD%BF%E7%94%A8%E9%81%87%E5%88%B0%E7%9A%84%E9%97%AE%E9%A2%98/" title="解决wsl2使用遇到的问题">
                        <span class="hidden-mobile">解决wsl2使用遇到的问题</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> <div style="font-size: 0.85rem"> <span id="timeDate">载入天数...</span> <span id="times">载入时分秒...</span> <script src="/js/duration.js"></script> </div> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>




  
<script src="//cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script>
<script src="//cdn.jsdelivr.net/gh/metowolf/Metingjs@1.2/dist/Meting.min.js"></script>
<script src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script>



<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
